

#import "InstallConfirmViewController.h"
//#import "ChanpinyeViewController.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "addhuiyuanViewController.h"
#import "shopcatCell.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "UIButton+WebCache.h"
#import "huiyuanDetailsViewController.h"
#import "GetProductListViewController.h"
#import "TheLoginViewController.h"
#import "shouyingViewController.h"
@interface InstallConfirmViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;

@property(nonatomic,retain)UIDatePicker* da;
@end

@implementation InstallConfirmViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*dealPrice;
    NSMutableArray*headImage;
    NSMutableArray*itemId;
    NSMutableArray*itemName;
    NSMutableArray*quantity;
    NSMutableArray*salePrice;
    NSMutableArray*specId;
    NSMutableArray* specName;
    NSMutableArray* specPrice;
    NSMutableArray* shopCartIds;
    NSMutableArray*isSelect;
      NSMutableArray*itemCode;
    NSString *result;
    int pageNumber;
    MBProgressHUD *progressHud;
    UIView* backview1;
    UIScrollView*myscrollView;
    NSString* sous;
    int pageNumber1;
    int pageNumber2;
    NSString*meiyousuos;
    UIView*view3;
    UIView*myToolBar;
    UIButton* sxBtn;
    UIButton*jiazai;
    float lastContentOffset;
    UIButton*hejibuyBtn1;
    UIButton*kong;
    UIButton*kong1;
    UIButton*buyBtn2;
    UIButton*xuanze;
    BOOL saveAccount;
    BOOL saveAccount1;
    UIButton*xiugaiview;
    UILabel*shu;
    UITextField*openTimeTextFied;
    NSString*shopCartId;
    UIView*view1;
    UIView*view2;
    UIView*view4;
    UIView*view5;
    NSMutableArray *selectFeatureCodeArray;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    self.title=@"安装确认";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    [self add];
    
}


- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    [self addFooter];
    _table.delegate=self;
    _table.dataSource=self;
    [self.view addSubview:_table];
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    commdity=[HAODEsingleton shared];
    _da = [[UIDatePicker alloc] init];
    [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    _da.datePickerMode = UIDatePickerModeDate;
    _da.backgroundColor=[UIColor whiteColor];
    myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    selectFeatureCodeArray=[[NSMutableArray alloc]init];
}

- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd  HH:mm"];
    
  
    
    
    if ([openTimeTextFied isFirstResponder])
    {
        openTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        //        NSString* string2 = BirthDateTextFied.text;
        //        NSDateFormatter *dateFormatter2 = [[NSDateFormatter alloc] init];
        //        [dateFormatter2 setDateFormat: @"yyyy-MM-dd "];
        //        NSDate *destDate2= [dateFormatter2 dateFromString:string2];
        //        NSTimeInterval  timeInterval2 = [destDate2 timeIntervalSinceDate:[NSDate date]];
        //        //        NSLog(@"%f",timeInterval2);
        //
        //
        //
        //        time1=timeInterval2;
        //        if (time1<0 ) {
        //            BirthDateTextFied.text=nil;
        //            [self showAlertMessage:@"提料日期必须在第2天至第10天区间"];
        //        }
        //
        //        if (time1>864000 ) {
        //            BirthDateTextFied.text=nil;
        //            [self showAlertMessage:@"提料日期必须在第2天至第10天区间"];
        //        }
        
    }
    
}

-(void)add{
    
    
    
    self.sat=nil;
    
    
    pageNumber = 1;
    dealPrice= [[NSMutableArray alloc] init];
    headImage= [[NSMutableArray alloc] init];
    itemId= [[NSMutableArray alloc] init];
    itemName= [[NSMutableArray alloc] init];
    quantity= [[NSMutableArray alloc] init];
    salePrice= [[NSMutableArray alloc] init];
    specId= [[NSMutableArray alloc] init];
    specName = [[NSMutableArray alloc] init];
    specPrice = [[NSMutableArray alloc] init];
    shopCartIds= [[NSMutableArray alloc] init];
    isSelect= [[NSMutableArray alloc] init];
    itemCode= [[NSMutableArray alloc] init];

    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:commdity.orderId forKey:@"orderId"];
 
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
    [HttpRequest requestData:@"Business/Order/ToInstall" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                
                UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 250)];
                view.backgroundColor=zuiqianhuicolor;
                _table.tableHeaderView=view;
                UIView*views=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
                views.backgroundColor=[UIColor whiteColor];
                [view addSubview:views];
                UILabel *line1=[[UILabel alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, 0.35)];
                line1.backgroundColor=qianhuicolor;
                [view addSubview:line1];
                UILabel *line2=[[UILabel alloc] initWithFrame:CGRectMake(0, 40+10-0.35, ScreenWidth, 0.35)];
                line2.backgroundColor=qianhuicolor;
                [view addSubview:line2];
                
                UIButton*quanxuanze=[[UIButton alloc]initWithFrame:CGRectMake(15, 6, 30, 30)];
                [quanxuanze setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [quanxuanze setTitle:@"员工" forState:UIControlStateNormal ];
                quanxuanze.titleLabel.font=[UIFont systemFontOfSize:15];
                [view addSubview:quanxuanze];
                
                NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
                NSString* UserName = [user1 objectForKey:@"userName"];
                //                self.GuideCode = [user1 objectForKey:@"UserCode"];
                UIButton*daogouname1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-200,  25/2,180,15)];
                [daogouname1 setTitle:UserName forState:UIControlStateNormal];
                daogouname1.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                daogouname1.titleLabel.textAlignment=NSTextAlignmentRight;
                daogouname1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
                //[daogouname addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
                [daogouname1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [view addSubview:daogouname1];

                view1=[[UIView alloc]initWithFrame:CGRectMake(0, 50, ScreenWidth, 70)];
                view1.backgroundColor=[UIColor whiteColor];
                [view addSubview:view1];
                UILabel *line3=[[UILabel alloc] initWithFrame:CGRectMake(0, view1.bottom, ScreenWidth, 0.35)];
                line3.backgroundColor=qianhuicolor;
                [view addSubview:line3];
                UILabel *line4=[[UILabel alloc] initWithFrame:CGRectMake(0, view1.bottom+10-0.35, ScreenWidth, 0.35)];
                line4.backgroundColor=qianhuicolor;
                [view addSubview:line4];
                NSString *s12 = [NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderNo"]];
                UIFont *font12 = [UIFont systemFontOfSize:contenfot];
                CGSize size12 = CGSizeMake(320, 2000);
                CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
                UILabel*source=[[UILabel alloc]initWithFrame:CGRectMake(15, 25/2, labelsize12.width+5, 15)];
                source.text=[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderNo"]];
                source.textColor=[UIColor blackColor];
                source.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:source];
                
                
                UILabel*orderStatus=[[UILabel alloc]initWithFrame:CGRectMake(source.right, 25/2, 60, 15)];
                orderStatus.textAlignment=NSTextAlignmentCenter;
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderStatus"]] isEqualToString:@"N"]) {
                    orderStatus.textColor=hongsecolor;
                    orderStatus.text=[NSString stringWithFormat:@"%@",  @"未收款"];
                }if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderStatus"]] isEqualToString:@"Y"]) {
                    orderStatus.textColor=luseColor;
                    orderStatus.text=[NSString stringWithFormat:@"%@",  @"收全款"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderStatus"]] isEqualToString:@"P"]) {
                    orderStatus.textColor=luseColor;
                    orderStatus.text=[NSString stringWithFormat:@"%@",  @"收定金"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderStatus"]] isEqualToString:@"C"]) {
                    orderStatus.textColor=luseColor;
                    orderStatus.text=[NSString stringWithFormat:@"%@",  @" 已取消"];
                    
                }
                orderStatus.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:orderStatus];
                
                UILabel*deliveryStatus=[[UILabel alloc]initWithFrame:CGRectMake(orderStatus.right, 25/2, 65, 15)];
                deliveryStatus.textAlignment=NSTextAlignmentCenter;
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"deliveryStatus"]] isEqualToString:@"N"]) {
                    deliveryStatus.textColor=hongsecolor;
                    deliveryStatus.text=[NSString stringWithFormat:@"%@",  @"未配送"];
                }if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"deliveryStatus"]] isEqualToString:@"Y"]) {
                    deliveryStatus.textColor=luseColor;
                    deliveryStatus.text=[NSString stringWithFormat:@"%@",  @"已配送"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"deliveryStatus"]] isEqualToString:@"B"]) {
                    deliveryStatus.textColor=luseColor;
                    deliveryStatus.text=[NSString stringWithFormat:@"%@",  @"部分配送"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"deliveryStatus"]] isEqualToString:@"X"]) {
                    deliveryStatus.textColor=luseColor;
                    deliveryStatus.text=[NSString stringWithFormat:@"%@",  @"无需配送"];
                    
                }
                deliveryStatus.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:deliveryStatus];
                
                UILabel*installStatus=[[UILabel alloc]initWithFrame:CGRectMake(deliveryStatus.right, 25/2, 65, 15)];
                
                installStatus.textAlignment=NSTextAlignmentCenter;
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"installStatus"]] isEqualToString:@"N"]) {
                    installStatus.textColor=hongsecolor;
                    installStatus.text=[NSString stringWithFormat:@"%@",  @"未安装"];
                }if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"installStatus"]] isEqualToString:@"Y"]) {
                    installStatus.textColor=luseColor;
                    installStatus.text=[NSString stringWithFormat:@"%@",  @"已安装"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"installStatus"]] isEqualToString:@"B"]) {
                    installStatus.textColor=luseColor;
                    installStatus.text=[NSString stringWithFormat:@"%@",  @"部分安装"];
                }
                if ([[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"installStatus"]] isEqualToString:@"X"]) {
                    installStatus.textColor=luseColor;
                    installStatus.text=[NSString stringWithFormat:@"%@",  @"无需安装"];
                    
                }
                
                installStatus.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:installStatus];
                
                
                UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 85/2, 35, 15)];
                duogou.text=[NSString stringWithFormat:@"来源"];
                duogou.textColor=zhonghuiColor;
                duogou.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:duogou];
                
                NSString *s1 = [NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"source"]];
                UIFont *font1 = [UIFont systemFontOfSize:contenfot];
                CGSize size1 = CGSizeMake(320, 2000);
                CGSize labelsize1 = [s1 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
                
                UIButton*daogouname=[[UIButton alloc]initWithFrame:CGRectMake(duogou.right,  85/2,labelsize1.width+5,15)];
                [daogouname setTitle:[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"source"]] forState:UIControlStateNormal];
                daogouname.titleLabel.font=[UIFont systemFontOfSize:contenfot];
                daogouname.titleLabel.textAlignment=NSTextAlignmentLeft;
                daogouname.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
                [daogouname setTitleColor:shenhuicolor forState:UIControlStateNormal];
                [view1 addSubview:daogouname];
                
                
                UILabel* orderDate=[[UILabel alloc]initWithFrame:CGRectMake(daogouname.right, 85/2, 65, 15)];
                orderDate.text=@"下单日期";
                orderDate.textColor=zhonghuiColor;
                orderDate.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:orderDate];
                NSRange range={0,10};
                NSString* string =[[[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"orderDate"] substringWithRange:range];
                UILabel* orderDate1=[[UILabel alloc]initWithFrame:CGRectMake(orderDate.right, 85/2, 180, 15)];
                orderDate1.text=[NSString stringWithFormat:@"%@",   string];
                orderDate1.textColor=shenhuicolor;
                orderDate1.font=[UIFont systemFontOfSize:contenfot];
                [view1 addSubview:orderDate1];
                
                
                
                
                view2=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+10, ScreenWidth, 70)];
                view2.backgroundColor=[UIColor whiteColor];
                [view addSubview:view2];
                UILabel *line5=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom, ScreenWidth, 0.35)];
                line5.backgroundColor=qianhuicolor;
                [view addSubview:line5];
                UILabel *line6=[[UILabel alloc] initWithFrame:CGRectMake(0, view2.bottom+10-0.35, ScreenWidth, 0.35)];
                line6.backgroundColor=qianhuicolor;
                [view addSubview:line6];

                NSString *s = [NSString stringWithFormat:@"%@(%@)",   [[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"memberName"],[[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"phone"]];
                UIFont *font = [UIFont systemFontOfSize:contenfot];
                CGSize size = CGSizeMake(320, 2000);
                CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
                UILabel*huiyuanname=[[UILabel alloc]initWithFrame:CGRectMake(15, 15, labelsize.width+3, 16)];
                huiyuanname.text=[NSString stringWithFormat:@"%@(%@)",   [[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"memberName"],[[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"phone"]];
                huiyuanname.textColor=[UIColor blackColor];
                huiyuanname.font=[UIFont systemFontOfSize:contenfot];
                [view2 addSubview:huiyuanname];
                
                UIImageView*Seximage=[[UIImageView alloc]initWithFrame:CGRectMake(huiyuanname.right, 15, 20, 20)];
                if (![[[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"sex"] isEqual:[NSNull null]]) {
                    
                    if ([[[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"sex"]isEqualToString:@"男"]) {
                        Seximage.image=[UIImage imageNamed:@"nan"];
                        
                        
                    }else{
                        Seximage.image=[UIImage imageNamed:@"nv"];
                    }
                    
                    
                }else{
                    Seximage.image=[UIImage imageNamed:@"nv"];
                    
                    
                }
                
                [view2 addSubview:Seximage];
                
                
                
                
                
                huiyuanname=[[UILabel alloc]initWithFrame:CGRectMake(15, 30, ScreenWidth-30, 30)];
                huiyuanname.text=[NSString stringWithFormat:@"%@",   [[severDataDict.dataDict objectForKey:@"member"] objectForKey:@"address"]];
                huiyuanname.textColor=shenhuicolor;
                huiyuanname.numberOfLines=2;
                huiyuanname.font=[UIFont systemFontOfSize:contenfot];
                [view2 addSubview:huiyuanname];
                
                
                
                view3=[[UIView alloc]initWithFrame:CGRectMake(0, view2.bottom+10, ScreenWidth, 45)];
                view3.backgroundColor=[UIColor whiteColor];
                [view addSubview:view3];
                
                
                UILabel*shangpingxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 80, 45)];
                shangpingxinxi.text=@"商品信息";
                shangpingxinxi.textColor=[UIColor blackColor];
                shangpingxinxi.font=[UIFont systemFontOfSize:sixteenORfifteenFot];
                [view3 addSubview:shangpingxinxi];
                UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 45-0.35, ScreenWidth-30, 0.35)];
                lineLabel1.backgroundColor=qianhuicolor;
                [view3 addSubview:lineLabel1];
                
             
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                arrr=[severDataDict.dataDict objectForKey:@"orderItem"];
                for (NSDictionary* dicc in arrr )
                {
                    [dealPrice addObject:[dicc valueForKey:@"dealPrice"]];
                    [headImage addObject:[dicc valueForKey:@"headImageFull"]];
                    [itemId addObject:[dicc valueForKey:@"itemId"]];
                    [itemName addObject:[dicc valueForKey:@"itemName"]];
                    [quantity addObject:[dicc valueForKey:@"quantity"]];
                    [salePrice addObject:[dicc valueForKey:@"salePrice"]];
                    [specId addObject:[dicc valueForKey:@"specId"]];
                    [shopCartIds addObject:[dicc valueForKey:@"id"]];
                    [specName addObject:[dicc valueForKey:@"specName"]];
                    [specPrice addObject:[dicc valueForKey:@"specPrice"]];
                    
                     [itemCode addObject:[dicc valueForKey:@"itemCode"]];
                }
                
                
                
                NSNumber*Total =  [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"totalMoney"];
                
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:Total.doubleValue]];
                UILabel* weightke=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-250, 0, 230, 45)];
                weightke.text=[NSString  stringWithFormat:@"共 %ld 件   ￥%@",arrr.count, formattedNumberString];
                weightke.textColor = [UIColor colorWithRed:5.00/255.0 green:18.0/255.0 blue:40.00/255.0 alpha:1];
                weightke.textAlignment = NSTextAlignmentRight;
                weightke.font = [UIFont systemFontOfSize:16];
                
                
                
                NSMutableAttributedString *AttributedStr2 = [[NSMutableAttributedString alloc]initWithString:[NSString  stringWithFormat:@"共 %ld 件   ￥%@",arrr.count, formattedNumberString]];
                
                [AttributedStr2 addAttribute:NSFontAttributeName
                 
                                       value:[UIFont systemFontOfSize:13.0]
                 
                                       range:NSMakeRange(0, 7)];
                
                [AttributedStr2 addAttribute:NSForegroundColorAttributeName
                 
                                       value:zhonghuiColor
                 
                                       range:NSMakeRange(0, 7)];
                
                
                weightke.attributedText = AttributedStr2;
                [view3 addSubview:weightke];
                

                
                
                UIView*footview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 250)];
                footview.backgroundColor=[UIColor whiteColor];
//                _table.tableFooterView=footview;
                UIView*vi=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 10)];
                vi.backgroundColor=zuiqianhuicolor;
                [footview addSubview:vi];
                UILabel *line7=[[UILabel alloc] initWithFrame:CGRectMake(0, 10-0.35, ScreenWidth, 0.35)];
                line7.backgroundColor=qianhuicolor;
                [footview addSubview:line7];
                UILabel*anzhuangxinxi=[[UILabel alloc]initWithFrame:CGRectMake(15, 20, 130, 30)];
                anzhuangxinxi .text= @"安装信息";
                anzhuangxinxi.font=[UIFont systemFontOfSize:15];
                [footview addSubview:anzhuangxinxi];


                UILabel*anzhuang=[[UILabel alloc]initWithFrame:CGRectMake(15, 50, 70, 45)];
                anzhuang .text= @"上门安装";
                anzhuang.font=[UIFont systemFontOfSize:15];
                [footview addSubview:anzhuang];

                
                openTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(anzhuang.right,  50, ScreenWidth,  45)];
                openTimeTextFied.borderStyle = UITextBorderStyleNone;
                openTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                openTimeTextFied.textColor=luseColor;
                openTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                openTimeTextFied.tag=2;
                openTimeTextFied.placeholder = @"请选择安装时间"; //默认显示的字
                openTimeTextFied.delegate = self;
                
                openTimeTextFied.text=[[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"installDate"];
                openTimeTextFied.textAlignment=NSTextAlignmentLeft;
                [openTimeTextFied setUserInteractionEnabled:YES];
                openTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [footview addSubview:openTimeTextFied];
                
               
                UIButton*jiantouBtn3 = [[UIButton alloc]init];
                jiantouBtn3.frame = CGRectMake(ScreenWidth-30,68,8, 13);
                [jiantouBtn3 setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
                [footview addSubview:jiantouBtn3];
                
                
                
                
                UIView*details=[[UIView alloc]initWithFrame:CGRectMake(0, openTimeTextFied.bottom, ScreenWidth, 10)];
                details.backgroundColor=zuiqianhuicolor;
                details.layer.borderWidth = 0.35;
                details.layer.borderColor = qianhuicolor.CGColor;
                [footview addSubview:details];
                
                UILabel*details1=[[UILabel alloc]initWithFrame:CGRectMake(15, details.bottom+10, ScreenWidth-40, 45)];
                details1.text=@"说明";
                details1.textColor=shenhuicolor;
                details1.font=[UIFont systemFontOfSize:15];
                [footview addSubview:details1];
                //                UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,details.bottom+45, ScreenWidth-30, 0.5)];
                //                _xianview.image=[UIImage imageNamed:@"hengxian"];
                //                [footview addSubview:_xianview];
                //
                
                
                
                NSString *s2 = [NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"details"]];
                UIFont *font2 = [UIFont systemFontOfSize:15];
                CGSize size2 = CGSizeMake(ScreenWidth-30, 2000);
                CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
                
                UILabel*details2=[[UILabel alloc]initWithFrame:CGRectMake(20, details1.bottom+10, ScreenWidth-30, labelsize2.height)];
                details2.text=[NSString stringWithFormat:@"%@", [[severDataDict.dataDict objectForKey:@"order"] objectForKey:@"remark"]];
                details2.textColor=shenhuicolor;
                details2.numberOfLines=0;
                details2.font=[UIFont systemFontOfSize:15];
                [footview addSubview:details2];
                
                
                footview.frame=CGRectMake(0, 0, ScreenWidth, details2.bottom+100);
                
                _table.tableFooterView=footview;
                
                
                
                
                
                
                
                openTimeTextFied.inputView = _da;

                openTimeTextFied.inputAccessoryView = myToolBar;
                
                [_table reloadData];
                
    
               
                [hejibuyBtn1 removeFromSuperview];
                [buyBtn2 removeFromSuperview];
       
                hejibuyBtn1=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-45, ScreenWidth*430/750, 45)];
                [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"已选商品%@件",@"0"] forState:UIControlStateNormal];
                hejibuyBtn1.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
                [hejibuyBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                hejibuyBtn1.alpha=0.8;
                hejibuyBtn1.titleLabel.textAlignment=NSTextAlignmentLeft;
                
              
                    [self.view addSubview:hejibuyBtn1];
                    
                    buyBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*430/750, ScreenHeight-45, ScreenWidth*320/750, 45)];
                    [buyBtn2 setTitle:@"安装确认" forState:UIControlStateNormal];
                    buyBtn2.backgroundColor=luseColor;
                    [buyBtn2 addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                    
                    [buyBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.view addSubview:buyBtn2];
                    
                    
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                  
                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
                    [self.navigationController pushViewController:detailViewController animated:YES];
                }
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    

}


-(void)go:(UIButton*)sender
{
    
    GetProductListViewController*detailViewController = [[GetProductListViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
    
}

-(void)queren:(UIButton*)sender
{
    

    if (selectFeatureCodeArray.count < 1)
    {
        [self showAlertMessage:@"请选择商品"];
    }
    else
    {
        
        if ([openTimeTextFied.text length] <1)
        {
            [self showAlertMessage:@"请选择安装时间"];
        }
        else{
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            NSMutableDictionary *params = [NSMutableDictionary new];
            
            [params setValue:Token forKey:@"tokenId"];
            
           
             [params setValue:commdity.orderId forKey:@"orderId"];
              [params setValue:openTimeTextFied.text forKey:@"installDate"];
              [params setValue:selectFeatureCodeArray  forKey:@"orderItemIds"];
      
            
        NSLog(@"33333333====%@",params);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:20 view:self.view];
            
            [HttpRequest requestData:@"Business/Order/InstallConfirm" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    
                    NSLog(@"33333333====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        
                        [self.navigationController popViewControllerAnimated:YES];
                        
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
    
    
    
        }}
    
    
    
    
    
    
}





//上拉刷新
- (void)addFooter
{
    
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
    
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [itemId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    shopcatCell* cell = (shopcatCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"shopcatCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    
    cell.saveAccount=YES;
    [cell.imageview.layer setCornerRadius:4.0];
    [cell.imageview.layer setBorderWidth:0.3];
    [cell.imageview.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [cell.imageview.layer setBorderColor:colorref2];//边框颜色
    [cell.imageview setImageWithURL:[NSURL URLWithString:[headImage objectAtIndex:indexPath.row]] placeholderImage:[UIImage imageNamed:@""]];
    

    
    cell.shopCartId=[shopCartIds objectAtIndex:indexPath.row];
    
    cell.title.text =[NSString stringWithFormat:@"%@%@",  [itemCode objectAtIndex:indexPath.row],[itemName objectAtIndex:indexPath.row]];
    cell.title.font=[UIFont systemFontOfSize:16];
    cell.title.textColor=[UIColor blackColor];
    
    cell.title.numberOfLines=2;
    
    
    if ([[specName objectAtIndex:indexPath.row]isEqualToString:@""]) {
        cell.guige.text =[NSString stringWithFormat:@"%@", @" "];

    }else{
        cell.guige.text =[NSString stringWithFormat:@"%@", [specName objectAtIndex:indexPath.row]];}
    cell.guige.font=[UIFont systemFontOfSize:15];
    cell.guige.textColor=zhonghuiColor;
    
    
    
    cell.shuliang.text =[NSString stringWithFormat:@"%.f",  [[quantity objectAtIndex:indexPath.row]floatValue]];
    cell.shuliang.font=[UIFont systemFontOfSize:15];
    
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
    cell.jiage.text =[NSString stringWithFormat:@"￥%@",  formattedNumberString];
    cell.jiage.font=[UIFont systemFontOfSize:eighteenthORfifteenFot];
    cell.jiage.textColor=hongsecolor;
    cell.xiugaijiage=[NSString stringWithFormat:@"%@",[dealPrice objectAtIndex:indexPath.row]];
//    cell.isSelect=[NSString stringWithFormat:@"%@",[isSelect objectAtIndex:indexPath.row]];
//    
//    if ([[isSelect objectAtIndex:indexPath.row]isEqualToString:@"Y"]) {
//        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
//    }else{
//        
//        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
//        
//    }
//    [cell.xuanzeBtn addTarget:self action:@selector(xuanzeBtn:) forControlEvents:UIControlEventTouchUpInside];
//
   
//   [cell.xiugai addTarget:self action:@selector(xiugai:) forControlEvents:UIControlEventTouchUpInside];
    if  ([selectFeatureCodeArray containsObject:[shopCartIds objectAtIndex:indexPath.row]]){
        
       
        [cell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        cell.saveAccount=NO;
        
    }
    [cell.xuanzeBtn setUserInteractionEnabled:NO];
    if (itemId.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 120-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (itemId.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 120-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=qianhuicolor;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  120;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    shopcatCell *sharecell=(shopcatCell *)cell;
    sharecell.saveAccount=! sharecell.saveAccount;
    
    if (!sharecell.saveAccount) {
        
        [selectFeatureCodeArray addObject:[shopCartIds objectAtIndex:indexPath.row]];
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shopcatCell *sharecell=(shopcatCell *)cell;
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
        
    }
    else{
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        shopcatCell *sharecell=(shopcatCell *)cell;
        [sharecell.xuanzeBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
        
        if (selectFeatureCodeArray.count>0) {
            
            for (int i=0; i<selectFeatureCodeArray.count; i++) {
                
                NSString *codeStr = [selectFeatureCodeArray objectAtIndex:i];
                if ([codeStr isEqualToString:[shopCartIds objectAtIndex:indexPath.row]] ) {
                    
                    [selectFeatureCodeArray removeObjectAtIndex:i];//从指定索引移除
                    
                }
            }
        }
    }
    [_table deselectRowAtIndexPath:indexPath animated:YES];
    [hejibuyBtn1 setTitle:[NSString stringWithFormat:@"已选商品%ld件",selectFeatureCodeArray.count] forState:UIControlStateNormal];
    
    NSLog(@"--＝＝＝＝＝＝-------%@",selectFeatureCodeArray);

}
//选择按钮
//选择按钮

-(void)xuanzeBtn:(UIButton*)sender{
    
    UIButton* button=(UIButton * )sender;
    shopcatCell* cell=(shopcatCell* )button.superview.superview;
    shopCartId=cell.shopCartId;
    

    
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
-(void)OnTapDone{
    
    
    [openTimeTextFied resignFirstResponder];
    
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    _table .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
   
    if (textField.tag == 2)
    { [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        _table .frame =CGRectMake(0, -150, ScreenWidth, ScreenHeight);
        [UIView commitAnimations];
        
        
    }
    
}
-(void)jiazai1{
    [jiazai removeFromSuperview];
    
    
}

@end
